<?php
/**
 * ClassName:
 * @auditor:leijunxiang
 * @time 2025/4/2 10:33
 */

namespace app\modelOperate\freightForward;

use app\modelOperate\ModelOpeBase;
use think\facade\Log;

class ChannelOpe extends ModelOpeBase
{

    protected $pk = 'channelId';
    /**
     * 保存数据
     * @param $data
     * @return void
     */
    public function saveData($data)
    {
        $db = $this->getDb();
        $flag = $db->insert($data);
        return $flag;
    }


    /**
     * 根据id查询数据
     * @return mixed
     */
    public function selectDataByForwardId($forwardId,$page,$limit)
    {
        $db = $this->getDb();
        $data = $db
            ->where('forwardId', '=', $forwardId)
            ->page($page,$limit)
            ->select();
        return $data;
    }

    /**
     * 根据货代id查询渠道数据(货代id)
     */
    public function selectChannelDataByForwardId($forwardId)
    {
        $db = $this->getDb();
        $data = $db
            ->where('forwardId', '=', $forwardId)
            ->select();
        return $data;
    }

    /**
     * 根据渠道名称查询id(渠道名称,货代id)
     */
    public function selectDataByChannelName($channelName,$forwardId)
    {
        $db = $this->getDb();
        $data = $db
            ->where('channelName', '=', $channelName)
            ->where('forwardId', '=', $forwardId)
            ->field('channelId')
            ->find();
        return $data;
    }

    /**
     * 根据货代id查询数量
     * @param $channelId
     * @return mixed
     */
    public function selectCount($forwardId)
    {
        $db = $this->getDb();
        $count = $db
            ->where('forwardId', '=', $forwardId)
            ->count();
        return $count;
    }

    /**
     * 删除数据
     * @param $channelId
     * @return mixed
     */
    public function delData($channelId)
    {
        $db = $this->getDb();
        $flag = $db->where('channelId', '=', $channelId)->delete();
        return $flag;
    }

    /**
     * 修改渠道名称
     * @param $channelId
     * @param $channelName
     * @return mixed
     */
    public function updateChannelData($channelId,$channelName)
    {
        $db = $this->getDb();
        $flag = $db->where('channelId', '=', $channelId)->update(['channelName'=>$channelName]);
        return $flag;
    }


}